package palms.messages;

import java.io.IOException;
import java.net.Socket;

import palms.exceptions.InvalidClassMessage;
import palms.exceptions.InvalidTicketMessage;
import palms.exceptions.InvalidUserMessage;
import palms.security.PalmsSecurityManager;

public class AuthRequest extends PMessage {


	private static final long serialVersionUID = 6693591932919327182L;

	private String username;

	public AuthRequest(String username) {
		super();
		this.username = username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getUsername() {
		return username;
	}
	
	public void sendTroughSocket(Socket s) throws IOException{
		PalmsSecurityManager.sendObjectTroughtSocket(s, this);
	}
	
	public static AuthRequest receiveTroughSocket(Socket s) throws IOException, ClassNotFoundException, InvalidClassMessage, InvalidUserMessage, InvalidTicketMessage{
		Object o = PalmsSecurityManager.receiveObjectTroughSocket(s);
		if(!(o instanceof AuthRequest))
			PalmsSecurityManager.throwCommException(o);
		else{
			AuthRequest ar = (AuthRequest)o;
			return ar;
		}
		return null;
	}
	
}
